const xmlreader = require('bbb-recording-xmlreader');
module.exports = class metaxml {
    constructor(file) {
        Object.defineProperty(this, '$', {
            writable: false,
            enumerable: false,
            value: xmlreader.loadXml(file)
        });
        Object.defineProperty(this, 'root', {
            writable: false,
            enumerable: false,
            value: this.$('recording')
        });
    }

    get originServerName() {
        let serName = this.root.find('meta originservername');
        let url = serName.length ? serName.text() : this.root.find('meta bbb-origin-server-name').text();
        return url;
    }

    get origin() {
        let origin = this.root.find('meta origin');
        if (origin.length) {
            return origin.text();
        }
        return this.root.find('meta bbb-origin').text();
    }

    get courseName() {
        let coursename = this.root.find('meta bbb-context').text();
        if (coursename)
            return coursename;
        return '';
    }

    get isMoodle() {
        return this.origin === 'Moodle';
    }

    get isWordpress() {
        return this.origin === 'WordPress';
    }

    get id() {
        return this.root.find('id').text();
    }

    get state() {
        return this.root.find('state').text();
    }

    get published() {
        return this.root.find('published').text();
    }

    get startTime() {
        return this.root.find('start_time').text();
    }

    get endTime() {
        return this.root.find('end_time').text();
    }

    get participants() {
        return this.root.find('participants').text();
    }

    get externalId() {
        return this.root.find('meeting[externalId]').val();
    }

    get name() {
        return this.root.find('meeting[name]').val();
    }

    get duration(){
        return this.root.find('playback duration').text();
    }

};


